﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wicresoft.UnifyShow.Business;
using Oracle.DataAccess.Client;

namespace Wicresoft.UnifyShow.BusinessImpl
{
    public class User : Basic, IUser
    {
        public List<Wicresoft.UnifyShow.Business.UserModel> GetListUserByName(string name)
        {
            QueryParameter[] attParam = new QueryParameter[] {
                        new QueryParameter(){ OracleDbColumnName="NAME", OracleDbColumnType=OracleDbType.NVarchar2,
                        OracleDbColumnSize=256,OracleDbColumnValue=name,QueryOperator=QueryOperatorType.like,PredicateType=PredicateType.where},
                    };
            return ModelHelper<UserModel>.GetModel_By_QueryParams(attParam, null, null, null, oda);
        }


        public List<UserModel> GetListUserByRole(string roleName)
        {
            OracleDataAccess oda = new OracleDataAccess();
            QueryParameter[] attParam = new QueryParameter[] {
                    new QueryParameter(){ OracleDbColumnName="name", OracleDbColumnType=OracleDbType.NVarchar2, OracleDbColumnSize=20,OracleDbColumnValue="Name",QueryOperator=QueryOperatorType.like},
                    };

            JoinCauses joins = new JoinCauses();
            JoinCause c1 = new JoinCause();
            c1.Alia = "a";
            c1.TableName = "Role";
            c1.Type = JoinType.inner;
            c1.AddQueryParameter(new QueryParameter()
            {
                OracleDbColumnName = "RoleName",
                OracleDbColumnType = OracleDbType.NVarchar2,
                OracleDbColumnSize = 20,
                OracleDbColumnValue = roleName,
                QueryOperator = QueryOperatorType.like,
                PredicateType = PredicateType.where
            });
            c1.AddOnQuery(new OnQueryParameter()
            {
                AliaLeft = "a",
                AliaRight = "b",
                ColumnNameLeft = "ID",
                ColumnNameRight = "RoleID"
            });

            JoinCause c2 = new JoinCause();
            c2.Alia = "b";
            c2.TableName = "UsersInRoles";
            c2.Type = JoinType.inner;
            c2.AddOnQuery(new OnQueryParameter()
            {
                AliaLeft = "z",
                AliaRight = "b",
                ColumnNameLeft = "ID",
                ColumnNameRight = "UseerID"
            });
            joins.Add(c2);
            joins.Add(c1);

            return ModelHelper<UserModel>.GetModel_By_QueryParams(attParam, null, null, null, oda, joins);

        }
    }
}
